import expandRow from './roleList';

export const roleData = [
    {
        id: '126991329',
        role: '管理员',
        user_num: 3,
        access: {
            topology: ['topology'],
            performance: ['performance-AC', 'performance-AP', 'performance-client', 'performance-services'],
            event: ['event-process', 'event-history'],
            analysis: ['analysis-network', 'analysis-AC', 'analysis-AP', 'analysis-client', 'analysis-event'],
            wiki: ['wiki'],
            access: ['access-role', 'access-user']
        },
        created_time: '2018-03-15 15:08:48',
        updated_time: '2018-03-15 15:08:48',
    },
    {
        id: '126991329',
        role: '一般运维人员',
        user_num: 3,
        access: {
            topology: ['topology'],
            performance: ['performance-AC', 'performance-AP', 'performance-client', 'performance-services'],
            event: ['event-process', 'event-history'],
            analysis: ['analysis-network', 'analysis-AC', 'analysis-AP', 'analysis-client', 'analysis-event'],
            wiki: ['wiki'],
            access: []
        },
        created_time: '2018-03-15 15:08:48',
        updated_time: '2018-03-15 15:08:48',
    },
];

export const generateRoleColumns = (editCB, deleteCB) => {
    return [
        {
            type: 'expand',
            width: 50,
            render: (h, params) => {
                return h(expandRow, {
                    props: {
                        row: params.row
                    }
                });
            }
        },
        {
            'title': '角色',
            'key': 'role'
        },
        {
            'title': '用户数',
            'key': 'user_num',
            render: (h, params) => {
                return h('a', { domProps: { href: '#/access/access-user' } }, params.row.user_num);
            },
            sortable: true
        },
        {
            'title': '创建时间',
            'key': 'created_time',
            sortable: true
        },
        {
            'title': '更新时间',
            'key': 'updated_time',
            sortable: true
        },
        {
            title: '操作',
            key: 'action',
            width: 100,
            render: (h, params) => {
                return h('div', [
                    h('Button', {
                        style: {
                            marginRight: '12px'
                        },
                        props: {
                            type: 'warning',
                            size: 'small'
                        },
                        on: {
                            click() { editCB(params.row); }
                        }
                    }, [h('Icon', { props: { type: 'edit' } })]),
                    h('Button', {
                        props: {
                            type: 'error',
                            size: 'small'
                        },
                        on: {
                            click() { deleteCB(params.row); }
                        }
                    }, [h('Icon', { props: { type: 'trash-a' } })])
                ]);
            }
        }
    ];
};
